// 点击返回 / 返回上一个页面
function backFn(){
	history.back();
}

// 点击 价格 和 作品信息  / 切换动画
var price = $(".list_top .art_price"),
		art_info = $(".list_top .art_art_info");
art_info.on("click",function(){
	if(art_info.find("span").css("border-bottom") == "0px none rgb(0, 0, 0)"){
		art_info.find("span").css("border-bottom","3px solid #000");
		price.find("span").css("border-bottom","0px none rgb(0, 0, 0)");
		$(".list_bottom").animate({"left":"-500px"},500);
	}
})
price.on("click",function(){
	if(price.find("span").css("border-bottom") == "0px none rgb(0, 0, 0)"){
		price.find("span").css("border-bottom","3px solid #000");
		art_info.find("span").css("border-bottom","0px none rgb(0, 0, 0)");
		$(".list_bottom").animate({"left":"0"},500);
	}
})


// 鼠标移到分享上 / 显示list
var shareBtn = $(".share_box");
shareBtn.on("mouseover",function(){
	$(".list_box").each(function(i){
		$(this).delay(i*200).fadeIn(500);
	})
}).on("mouseout",function(){
	$(".list_box").each(function(i){
		$(this).delay(i*200).fadeOut(500);
	})
})

// 点击联系客服 / 打开留言弹出框
var contact_service = $(".contact_service");
contact_service.on("click",function(){
	$(this).css({"display":"none"});
	$(".leave_message").css({"display":"block"});
})

// 点击关闭和最小化 / 关闭隐藏留言框
var leave_message_btn = $(".leave_msg_top img");
leave_message_btn.on("click",function(){
	$(".leave_message").css({"display":"none"});
	contact_service.css({"display":"block"});
})

// 移动留言框
var leave_message = $(".leave_message"),
		x1 = 0,
		y1 = 0;
leave_message.on("dragstart",function(){
	x1 = event.offsetX;
	y1 = event.offsetY;
	console.log(x1,y1);
}).on("drag",function(){
	var x2 = event.pageX,
      y2 = event.pageY;
  console.log(x2,y2);
  $(this).offset({
    top:y2 - y1,
    left:x2 - x1
  })
}).on("dragend",function(){
	var x2 = event.pageX,
      y2 = event.pageY;
  console.log(x2,y2);
  $(this).offset({
    top:y2 - y1,
    left:x2 - x1
  })
})

// 点击放大作品
var big_art = $(".art_left img");
big_art.on("click",function(){
	$("section").css({"display":"none"});
	$(".section_hidden").css({"display":"block"});
})

// 点击放大页面 / 关闭按钮
var close_btn = $(".section_hidden .close");
close_btn.on("click",function(){
	$("section").css({"display":"block"});
	$(".section_hidden").css({"display":"none"});
})

// 点击放大页面 / 放大按钮
var move_big_btn = $(".section_hidden .fangda");
move_big_btn.on("click",function(){
	var control_btn = $(".section_hidden .xia span");
	var p = Number(control_btn.css("left").search("p")),
			left = Number(control_btn.css("left").slice(0,p)),
			h_P = Number($(".section_hidden .big_art_photo").css("height").search("p")),
			h = Number($(".section_hidden .big_art_photo").css("height").slice(0,h_P));
	console.log(h);
	if(left < 111){
		control_btn.css({
			"left": left + 27 + "px"
		})
		$(".section_hidden .big_art_photo").css({
			"height":h + 200 + "px",
		})
	}else{
		control_btn.css({
			"left":"111px"
		})
	}
})

// 点击放大页面 / 缩小按钮
var move_small_btn = $(".section_hidden .suoxiao");
move_small_btn.on("click",function(){
	var control_btn = $(".section_hidden .xia span");
	var p = Number(control_btn.css("left").search("p")),
			left = Number(control_btn.css("left").slice(0,p)),
			h_P = Number($(".section_hidden .big_art_photo").css("height").search("p")),
			h = Number($(".section_hidden .big_art_photo").css("height").slice(0,h_P));
	console.log(left);
	if(left > 30){
		control_btn.css({
			"left": left - 27 + "px"
		})
		$(".section_hidden .big_art_photo").css({
			"height":h - 200 + "px"
		})
	}else{
		control_btn.css({
			"left":"30px"
		})
	}
})

// 获取当前页面的id
var test = window.location.search;
console.log(test);
test.slice(1,5);
var p_id = test.slice(4);
console.log(p_id);

// 获取作品信息
var arts = art_data.content_name;
console.log(arts)
for(var i = 0;i< arts.length;i++){
	// 获取上一页面鼠标点击的作品信息
	var _name = arts[i].art_name,
      _genre = arts[i].art_genre,
      _artist = arts[i].art_artist,
      _size = arts[i].art_size,
      _price = arts[i].art_price,
      _site = arts[i].art_site,
      _id = arts[i].id;     // 获取上一页面鼠标点击的作品对应的id值
  if(_id == p_id){   //找出遍历对象中 与 上一页面作品对应的id值相等的  id值  
  										//如果相等给add_car 页面作品添加id值对应的作品信息
  	// 获取页面中作品信息
  	var art_name = $(".art_info .art_name"),
  			art_genre = $(".art_info .genre"),
  			art_price = $(".list_bottom .price h2").find("span"),
  			art_artist = $(".art_info .name a"),
  			art_size = $(".art_info").find(".size"),
  			art_site = $(".art_left .art_site");
  	art_name.text(_name);
  	art_genre.text(_genre + "，");
  	art_price.text(_price);
  	art_artist.text(_artist);
  	art_size.text(_size);
  	art_site.attr("src",_site);
  	$(".section_hidden img").attr("src",_site);
  	$(".photo_thumb").css({
  		"background-image":"url("+_site+")"
  	})
  }
}

